/* Syntax to generate analyses in "Knowing When to Splurge: Precautionary Saving and Chinese-Canadians" */

/* Note: The raw data file must be located in the current directory/folder. */

/* 1. Load raw data */
use SavingExperiment-MangerMatthews-Rawdata.dta, clear			

/* 2. Generate Figure 1 */
set scheme plotplain
reg dospertf o1.cycle i.chin i.trmt fem i.agecat ont bc i.educ2 i.income i.wealth, vce(cl responseid)
margin income#chin if income!=6, l(90)
marginsplot, ti("") yti("Predicted financial risk-taking")

/* 3. Generate Table 1 */
reg savings o1.cycle i.trmt fem i.agecat ont bc i.educ2 i.income i.wealth dospertf, vce(cl responseid)
eststo m1
reg savings o1.cycle i.chin i.trmt fem i.agecat ont bc i.educ2 i.income i.wealth dospertf, vce(cl responseid)
eststo m2
reg savings o1.cycle i.chin##i.trmt fem i.agecat ont bc i.educ2 i.income i.wealth dospertf, vce(cl responseid)
eststo m3
reg savings o1.cycle i.chinlang i.trmt fem i.agecat ont bc i.educ2 i.income i.wealth dospertf, vce(cl responseid)
eststo m4
reg savings o1.cycle i.chinlang##i.trmt fem i.agecat ont bc i.educ2 i.income i.wealth dospertf, vce(cl responseid)
eststo m5
estout  _all, cells(b(nostar fmt(3)) p(par fmt(3)) ) drop(1bn* 0bn* *#0bn*) order(1.trmt 1.chin 1.chinlang *1.trmt dospertf) style(fixed) replace /*
*/ varwidth(20) leg label s(r2 N, fmt(3 0))

/* 4. Generate Figure 2 (n.b., This syntax assumes the stored estimates from 3, above.) */
set scheme plotplain
coefplot (m1, keep(1.trmt) label("1")) (m2, keep(1.chin 1.trmt) label("2")) (m3, keep(1.chin 1.trmt 1.chin#1.trmt) label("3")) /*
*/ (m4, keep(1.chinlang 1.trmt) label("4")) (m5, keep(1.chinlang 1.trmt 1.chinlang#1.trmt) label("5")), /*
*/coeflabels(1.trmt="Insurance" 1.chin="Chinese ethnicity" 1.chinlang="Chinese speaker" 1.chin#1.trmt= /*
*/"Ethnicity * Insurance" 1.chinlang#1.trmt= "Speaker * Insurance", wrap(12)) xline(0) leg(ti("Model:"))

/* 5. Generate Figure 3 */
reg savings o1.cycle i.trmt fem i.agecat ont bc i.educ2 i.income i.wealth dospertf, vce(cl responseid)
set scheme plotplain
margin agecat if agecat~=7
marginsplot, ti("") yti("Predicted final savings (adj.)") xti("Age band")
